import { Application } from 'egg';

export default (app: Application) => {
  const { controller, router } = app;
  const AuthMiddleware = app.middleware.auth();

  // 主页
  router.get('/api/home', controller.home.index);

  // 登录
  router.post('/api/user/login', app.passport.authenticate('local', { successRedirect: '/api/home' }));
  // 注册
  router.post('/api/user/create', controller.user.create);
  // 登出
  router.post('/api/user/logout', AuthMiddleware, controller.user.logout);

  // 当前登录用户详情
  router.get('/api/user/userInfo', AuthMiddleware, controller.user.userInfo);

  // 现象故障
  router.resources('fault', '/api/fault', AuthMiddleware, controller.fault);
};
